﻿{% extends "layout.html" %}

{% block head %}
{% endblock %}

{% block body %}
<table class="jobs" border="0" cellpadding="3" cellspacing="1">
	<tr>
		<th>Release name</th>
		<th>Source</th>
		<th>Size</th>
		<th>Edit</th>
	</tr>

	<tbody>
		{% for entry in entries %}
			<tr>
				<td class="name">
					<a href="{{ entry.LogPageUrl }}"><img src={{ entry.StateIcon }} title="{{ entry.State }}"></a>

					<span class="title">
					{% if entry.PtpUrl %}
						<a href="{{ entry.PtpUrl }}">{{ entry.ReleaseName }}</a>
					{% else %}
						{{ entry.ReleaseName }}
					{% endif %}
					</span>

					{% if entry.ErrorMessage %}
						<br>
						{{ entry.ErrorMessage }}
					{% endif %}
				</td>
				<td>
					{% if entry.SourceIcon %}
						{% if entry.SourceUrl %}
							<a href="{{ entry.SourceUrl }}"><img src={{ entry.SourceIcon }}></a>
						{% else %}
							<img src={{ entry.SourceIcon }}>
						{% endif %}
					{% endif %}
				</td>
				<td>
					{{ entry.Size }}
				</td>
				<td>
					{% if entry.StartJobUrl %}
						<a href="#" onclick='executeJobCommand( this, {{ entry.Id }}, "/start/" ); return false;'><img src={{ url_for( "static", filename = "start.png" ) }} title="Start"></a>
					{% endif %}
					{% if entry.StopJobUrl %}
						<a href="#" onclick='executeJobCommand( this, {{ entry.Id }}, "/stop/" ); return false;'><img src={{ url_for( "static", filename = "stop.png" ) }} title="Stop"></a>
					{% endif %}
					{% if entry.EditJobUrl %}
						<a href="{{ entry.EditJobUrl }}"><img src={{ url_for( "static", filename = "edit.png" ) }} title="Edit"></a>
					{% endif %}
				</td>
			</tr>
		{% else %}
			<tr>
				<td>No entries.</td>
			</tr>
		{% endfor %}
	</tbody>
</table>

<div class="pagination">
	{% if pagination.has_prev %}
		<a href="{{ url_for_other_page( pagination.page - 1 ) }}">&laquo; Prev</a>
	{% endif %}
	{%- for page in pagination.iter_pages() %}
		{% if page %}
			{% if page != pagination.page %}
				<a href="{{ url_for_other_page( page ) }}">{{ page }}</a>
			{% else %}
				<strong>{{ page }}</strong>
			{% endif %}
		{% else %}
			<span class="ellipsis">…</span>
		{% endif %}
	{%- endfor %}
	{% if pagination.has_next %}
		<a href="{{ url_for_other_page( pagination.page + 1 ) }}">Next &raquo;</a>
	{% endif %}
</div>

<script type=text/javascript src="{{ url_for( "static", filename = "script/jquery-1.5.2.min.js" ) }}"></script>

<script type="text/javascript">
	var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};

	function executeJobCommand(linkNode, jobId, jobCommand)
	{
		$.ajax(
		{
			type: "GET",
			url: $SCRIPT_ROOT + "/jobs/" + jobId + jobCommand,
			context: linkNode,
			success: function(msg)
			{
				$(this).text( msg );
				if ( msg == "OK" )
					$(this).fadeOut( "slow" );
			}
		} );
	}
</script>
{% endblock %}